
package com.platform.modules.event;

import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.platform.common.annotation.SysLog;
import com.platform.common.utils.RestResponse;
import com.platform.modules.event.entity.MallReservationActivityEntity;
import com.platform.modules.event.service.MallReservationActivityService;
import com.platform.modules.event.vo.MallReservationActivityVo;
import com.platform.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * 预约活动Controller
 *
 * @author
 * @date 2023-04-20 10:26:24
 */
@RestController
@RequestMapping("mall/reservationactivity")
public class MallReservationActivityController extends AbstractController {
    @Autowired
    private MallReservationActivityService mallReservationActivityService;


    /**
     * 查看所有列表
     *
     * @param params 查询参数
     * @return RestResponse
     */
    @RequestMapping("/queryAll")
    @RequiresPermissions("mall:reservationactivity:list")
    public RestResponse queryAll(@RequestParam Map<String, Object> params) {
        List<MallReservationActivityEntity> list = mallReservationActivityService.queryAll(params);

        return RestResponse.success().put("list", list);
    }

    /**
     * 分页查询预约活动
     *
     * @param params 查询参数
     * @return RestResponse
     */
    @GetMapping("/list")
    @RequiresPermissions("mall:reservationactivity:list")
    public RestResponse list(@RequestParam Map<String, Object> params) {
        Page page = mallReservationActivityService.queryPage(params);

        return RestResponse.success().put("page", page);
    }

    /**
     * 根据主键查询详情
     *
     * @param id 主键
     * @return RestResponse
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("mall:reservationactivity:info")
    public RestResponse info(@PathVariable("id") String id) {
        MallReservationActivityEntity mallReservationActivity = mallReservationActivityService.getById(id);

        return RestResponse.success().put("reservationactivity", mallReservationActivity);
    }

    /**
     * 新增预约活动
     *
     * @param mallReservationActivity mallReservationActivity
     * @return RestResponse
     */
    @SysLog("新增预约活动")
    @RequestMapping("/save")
    @RequiresPermissions("mall:reservationactivity:save")
    public RestResponse save(@RequestBody MallReservationActivityEntity mallReservationActivity) {

        mallReservationActivityService.add(mallReservationActivity);

        return RestResponse.success();
    }

    /**
     * 修改预约活动
     *
     * @param mallReservationActivity mallReservationActivity
     * @return RestResponse
     */
    @SysLog("修改预约活动")
    @RequestMapping("/update")
    @RequiresPermissions("mall:reservationactivity:update")
    public RestResponse update(@RequestBody MallReservationActivityEntity mallReservationActivity) {

        mallReservationActivityService.update(mallReservationActivity);

        return RestResponse.success();
    }

    /**
     * 根据主键删除预约活动
     *
     * @param ids ids
     * @return RestResponse
     */
    @SysLog("删除预约活动")
    @RequestMapping("/delete")
    @RequiresPermissions("mall:reservationactivity:delete")
    public RestResponse delete(@RequestBody String[] ids) {
        mallReservationActivityService.deleteBatch(ids);

        return RestResponse.success();
    }

    /**
     * 导出
     *
     * @param params 查询参数
     * @return RestResponse
     */
    @GetMapping("/export")
    @RequiresPermissions("mall:reservationactivity:list")
    public void export(HttpServletResponse response, @RequestParam Map<String, Object> params) {
        try {
            List<MallReservationActivityVo> voList = mallReservationActivityService.queryAllExport(params);
            EasyExcel.write(response.getOutputStream(), MallReservationActivityVo.class)
                    .sheet("预约活动")
                    .doWrite(voList);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
